//得到食品的分类
AJAX({
    methods:'get',
    url:'https://elm.cangdu.org/v2/index_entry'
}).then((res)=>{
    getfoodclass(res)
})

//得到食品的展示
AJAX({
    methods:'get',
    url:'https://elm.cangdu.org/shopping/restaurants?latitude=31.22967&longitude=121.4762'
}).then((res)=>{
    getfoods(res)
})

//搜索栏
search.addEventListener('submit',(e)=>{
    e.preventDefault()//阻止刷新
    $('input')[0].value=''
    AJAX({
        methods:'get',
        url:'https://elm.cangdu.org/v1/cities/1'
    }).then((res)=>{
        console.log('hi')
        alert('搞笑，现在还不能搜索')
        //搜索事件，待填
    })
})

//获取食物类函数
function getfoodclass(x){
    x.forEach((item,index)=>{
        let food=document.createElement('li')
        let img1=document.createElement('img')
        let span=document.createElement('div')
        img1.src=item.image_url
        span.innerHTML=item.title        
        food.appendChild(img1) 
        food.appendChild(span)        
        Addclass(food,index)
    })
    $('li').addClass('food')
}
//分别展示食物类函数
function Addclass(foods,i){
    if(i<8){
        foodclass1.appendChild(foods)     
    }else{
        foodclass2.appendChild(foods)          
    }       
}
//获取食物展示的函数
function getfoods(x){
    x.forEach((item)=>{
        let food=document.createElement('div')
        let img=document.createElement('img')
        let name=document.createElement('div')
        let icons=document.createElement('div')
        let div1=document.createElement('div')
        let div2=document.createElement('div')       
        img.src='https://elm.cangdu.org/shopping/restaurants/164ad0b6a3917599.jpg'
        food.id='a'+item.id 
        name.innerHTML=item.name
        let icon=item.supports
        icon.forEach((item)=>{
            let iconna=document.createElement('div')
            iconna.innerText=item.icon_name
            icons.appendChild(iconna)
        })
        div1.innerHTML='评价'+item.rating
        div2.innerHTML=item.piecewise_agent_fee.tips     
        name.appendChild(icons)
        food.appendChild(img)
        food.appendChild(name)
        food.appendChild(div1)
        food.appendChild(div2)
        foods.appendChild(food)
    })
    $('#foods>div').addClass('food1')
    $('#foods>div>img').addClass('imgss')
    //这一行被写死了，已经写好了$('#foods>div>div').addClass('span')
}

